import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wallet_utils/base_router_config.dart';
import 'package:wallet_utils/color.dart';
import 'package:wallet_utils/dialog/double_dialog.dart';
import 'package:wallet_utils/ht_appbar.dart';
import 'package:wallet_utils/location/locationUtil.dart';
import 'package:wallet_utils/log_util.dart';
import 'package:wallet_utils/login_utils.dart';
import 'package:wallet_utils/report_widget/click_widget.dart';
import 'package:wallet_utils/text_style.dart';
import 'logic.dart';

class SettingPage extends StatelessWidget {
  final logic = Get.put(SettingLogic());
  final state = Get.find<SettingLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ColorManager.colorFFFFFF,
      appBar: htCommonAppbar(context, title: '设置'),
      bottomNavigationBar: ClickWidget(
        onTap: () {
          showDialog(
              context: context,
              builder: (context) {
                return DoubleDialog("账户注销前请结清全部欠款，否则注销将失败，"
                    "账户注销后将删除您全部数据且不可恢复，确认要注销吗？", yesStr: '确认注销', yesCallback: () {
                  logic.cancellation();
                  Get.back();
                },noStr: '再想想',noCallback: (){
                  Get.back();
                },);
              });
        },
        child: Container(
          color: ColorManager.colorF4F5F6,
          height: 50.w + ScreenUtil().bottomBarHeight,
          alignment: Alignment.center,
          padding: EdgeInsets.only(bottom: 30.w),
          child: Text(
            '注销账户',
            style: TextStyleUtils.style999999(fontSize: 14.sp),
          ),
        ),
      ),
      body: Container(
        color: ColorManager.colorF4F5F6,
        child: Column(
          children: [
            MediaQuery.removePadding(
                context: context,
                removeTop: true,
                removeBottom: true,
                child: Container(
                  margin: EdgeInsets.only(
                    top: 10.w,
                  ),
                  color: ColorManager.colorFFFFFF,
                  child: ListView.builder(
                    shrinkWrap: true,
                    itemCount: state.list.length,
                    physics: const NeverScrollableScrollPhysics(),
                    itemBuilder: ((context, index) {
                      return mineWidget(index);
                    }),
                  ),
                )),
            ClickWidget(
              onTap: (){
                logic.logOut();
              },
              child: Container(
                width: double.infinity,
                height: 62.w,
                alignment: Alignment.center,
                margin: EdgeInsets.only(top: 10.w),
                color: ColorManager.colorFFFFFF,
                child: Text(
                  '退出登录',
                  style: TextStyleUtils.style000000(fontSize: 16.sp),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget mineWidget(int index) {
    return ClickWidget(
      onTap: () {
        logic.mineCheck(index);
      },
      child: Column(
        children: [
          Container(
            height: 65.w,
            margin: EdgeInsets.only(left: 20.w, right: 20.w),
            child: Row(
              children: [
                Image.asset(
                  state.list[index].image ?? '',
                  width: 25.w,
                  height: 25.w,
                ),
                SizedBox(
                  width: 12.w,
                ),
                Expanded(
                    child: Text(
                  state.list[index].title ?? '',
                  style: TextStyleUtils.style000000(fontSize: 16.sp),
                )),
                Image.asset(
                  'images/user_arrow.png',
                  width: 13.w,
                  height: 13.w,
                ),
              ],
            ),
          ),
          index == state.list.length - 1
              ? Container()
              : Container(
                  height: 0.5.w,
                  margin: EdgeInsets.only(left: 20.w, right: 20.w),
                  color: ColorManager.colorECECEC,
                )
        ],
      ),
    );
  }
}
